﻿jQuery(document).ready(function ($) {
    function load(num) {
        var x = $("#showcaseItems a[href=#" + num + "]");
        previewShowcaseItem($(x));        
        prettyPrint();
    }
    
    $.history.init(function (url) {
        load(url == "" ? "Default" : url);
    });

    $("#showcaseItems a").live('click', function (e) {
        var url = $(this).attr('href');
        url = url.replace(/^.*#/, '');
        $.history.load(url);
        return false;
    });

    function previewShowcaseItem(element) {
        var li = $(element).parent();
        var exampleUrl = li.find('.example').val();
        var markup = li.find('.markup').val();
        var codeBehind = li.find('.codeBehind').val();

        $("#example").attr("src", exampleUrl);
        $("#markup").text(markup);
        $("#codeBehind").text(codeBehind);

        $.each($("#showcaseItems a"), function () {
            $(this).removeClass("disabled");
        });

        $(element).addClass('disabled');
    }    
});